{% extends "PlatBundle::layout.html.twig" %}

{% block title %}超链接管理{% endblock %}

{% block css %}

{% endblock %}


{% block top %}
    {{ parent() }}
{% endblock %}


{% block left_body_top %}
    {{ parent() }}
{% endblock %}


{% block left_body %}
    {{ parent() }}
{% endblock %}


    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">系统设置</span>
            </div>
            <div class="top-nav top-nav-active">超链接管理</div>
        </div>
        <div class="main-content">

            <div class="mes-content">

                <div class="main-mes-content">
                    <div class="al-released fl">超链接列表</div>

                    <table class="table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th style="width: 6%;" class="center-th">序号</th>
                            <th class="center-th">文字</th>
                            <th class="center-th">超链接</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>


                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">
                            <li><a href="#">&laquo;</a></li>
                            <li><a href="{{ path('plat_get_link') }}" class="mes-page-check">1</a></li>
                            <li><a href="#">&raquo;</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="pop-status opacity"></div>

    {% endblock %}


{% block body %}{% endblock %}

{% block box %}
    <!--新建文件夹信息-->
    <div class="pop-first pop-classify" style="display: none;">
        <div class="pop-title">编辑超链接
            <span class="close close-icon"></span>
        </div>
        <div id="classSubmit">
            <div style="padding: 30px 30px 0 30px;">
                <div class="com-left fl" style="width: 86px;">文字</div>
                <input type="text" class="com-select com-title" placeholder="请输入文字" style="width: 350px;padding: 0 15px;">

                <div class="com-left fl" style="width: 86px;">超链接</div>
                <input type="text" class="com-select com-url" placeholder="请输入超链接名称" style="width: 350px;padding: 0 15px;">

                <div class="add-mem-box" style="margin:30px 0;overflow: hidden;">
                    <div class="com-left fl"></div>
                    <div class="acc-opera-btn fl mem-btn classify-btn">保存</div>
                    <div class="acc-opera-btn fl mem-cancel">取消</div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}


{% block javascript %}
<script type="text/javascript">
    $(function () {

        SidebarHighlighting('8');
        SonSidebar("8","5");

        //点击取消
        $('.mem-cancel, .close-icon').on('click', function() {
            ComMesClose();
        });

        // 点击编辑
        $('body').on('click','.tab-edit', function() {
            var edit_url = $(this).data('url');
            $('.com-url').val(edit_url);
            var edit_key = $(this).data('key');
            $('.com-title').val(edit_key);
            ComMesOpen();
            $('.pop-classify').show();
        });

        function ComMesClose() {
            $('.pop-status').hide();
            $('.pop-classify').hide();
        }

        function ComMesOpen() {
            $('.pop-status').show();
        }

        // 获取超链接
        $.getJSON("{{ path('api_platform_get_link') }}",{},function(data){
            console.log(data);
            var html = '';
            var item = data.data.link;
            if(item == false){
                var link = "";
            } else {
                var link = item.config_value;
            }
            //π+派伽提供技术支持
            html += '<tr>';
            html += '<td class="a-line center-th">1</td>';
            html += '<td class="center-th">'+ data.data.link.config_key +'</td>';
            html += '<td class="center-th">'+ link +'</td>';
            html += '<td class="center-th">';
            html += '<span class="table-opera tab-edit" data-url="'+ link +'" data-key="'+ data.data.link.config_key +'">编辑</span>';
            html += '</td>';
            html += '</tr>';

            $("table tbody").append(html);

        })

        // 编辑超链接
        $(".mem-btn").click(function(){
            var edit_url = $('.com-url').val();
            var key_link = $('.com-title').val();

            if($.trim(key_link) == 0){
                popStatus(2, "文字不能为空", 1, '', true);
            }
            $.post("{{ path('api_platform_link_manager') }}",{link:edit_url,key_link:key_link},function (data) {
                console.log(data);
                if(data.errorCode == 0){
                    popStatus(1, data.message, 1, "", true);
                    location.reload();
                } else {
                    popStatus(2, data.message, 1, '', true);
                }

            })
        })
    })
</script>

{% endblock %}